// pages/index/moreMenu/moreMenu.js
//获取应用实例
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    iconList: [],
    MasterBizType: 1,
    BiztypeSort: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let self = this;
    self.setData(options)
    let url = app.apiBaseUrl + "/Common/GetMoreBizType";

    app.httpRequest({
      method: "GET",
      url: url,
      showLoading: true,
      data: {
        masterBizTypeId: self.data.MasterBizType,
        sort: self.data.BiztypeSort
      },
      success: function(res) {
        let rdata = res.data;
        if (rdata.status == 0) {
          console.log(rdata);
          self.setData({
            iconList: rdata.data
          });
        } else {
          wx.showToast({
            title: rdata.message,
            icon: 'none'
          });
        }
      }
    });
  },
  /**
   * 跳转页面
   */
  addRegister(e) {
    let self = this;
    let usr = app.userInfo;
    //已经获取授权
    let btype = e.currentTarget.dataset.btype;
    let urlpath = e.currentTarget.dataset.urlpath;
    let mtype = e.currentTarget.dataset.mtype;
    if (btype == "-1") {
      wx.navigateTo({
        url: '/pages/index/moreMenu/moreMenu?MasterBizType=' + mtype,
      })
    } else {
      self.getUnCompleteOrder(btype, urlpath);
    }
  },
  /**
 * 获取未完成的订单
 */
  getUnCompleteOrder(btype, urlpath) {
    let self = this;
    let url = app.apiBaseUrl + "/RegOrder/GetOrderId";
    app.httpRequest({
      method: "GET",
      url: url,
      showLoading: true,
      data: {
        userId: app.userInfo.UserID,
        bizTypeId: btype
      },
      success: function (res) {
        let rdata = res.data;
        if (rdata.status == 0) {
          if (rdata.data < 1) {
            wx.navigateTo({
              url: '/pages/index/mainOperation/order/guide/guide?BizTypeID=' + btype + '&NavigateUrl=' + urlpath,
            });
          } else {
            wx.showModal({
              title: '提示',
              content: '用户存在未完成订单,是否查看',
              success(res) {
                if (res.confirm) {
                  wx.navigateTo({
                    url: '/pages/index/mainOperation/order/orderDetails/orderDetails?OrderId=' + rdata.data,
                  })
                } else if (res.cancel) {
                  console.log('用户点击取消')
                }
              }

            })
          }
        } else {

        }
      }
    });
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})